home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Contributed / SpriteWorld / SpriteWorld Files / Headers / BlitPixieInterface.h next >
Encoding:
Text File  |  2000-10-06  |  11.2 KB  |  367 lines  |  [TEXT/CWIE]

  1. ///--------------------------------------------------------------------------------------
  2. //    BlitPixieInterface.h
  3. //
  4. //    Provides a SpriteWorld interface into the BlitPixie routines.
  5. ///--------------------------------------------------------------------------------------
  6.  
  7. #ifndef __BLITPIXIEINTERFACE__
  8. #define __BLITPIXIEINTERFACE__
  9.  
  10. #ifndef __SWCOMMON__
  11. #include <SWCommonHeaders.h>
  12. #endif
  13.  
  14.  
  15. ///--------------------------------------------------------------------------------------
  16. //    type definitions
  17. ///--------------------------------------------------------------------------------------
  18.  
  19. typedef struct StarArray
  20. {
  21.     short    horizLoc;            // Current horizontal position of the star
  22.     short    vertLoc;            // Current vertical position of the star
  23.     short    oldHorizLoc;        // Horizontal position of star the previous frame
  24.     short    oldVertLoc;            // Vertical position of star the previous frame
  25.     short    horizSpeed;            // To be used by the user to move the star
  26.     short    vertSpeed;            // To be used by the user to move the star
  27.     unsigned long    color;        // Current color of the star
  28.     Boolean    isOn;                // Draw this star ?
  29.     Boolean    needsToBeErased;    // If drawn last frame, then it needs to be erased.
  30.     short    userData;            // Reserved for user 
  31. } StarArray, *StarArrayPtr;
  32.  
  33.  
  34. #if PRAGMA_ALIGN_SUPPORTED
  35.     #pragma options align=packed
  36. #endif
  37.  
  38. struct RLEPixelData    // 'RLE#' resource
  39. {
  40.     unsigned short    width;        // pixel width (max for all frames)
  41.     unsigned short    height;        // pixel height (max for all frames)
  42.     unsigned short    depth;        // bit depth (8/16/32)
  43.     unsigned short    palette;    // color table 'clut' ID (0 for default)
  44.  
  45.     unsigned short    frames;        // number of frames in this resource
  46.     unsigned short    reserved1;
  47.     unsigned short    reserved2;
  48.     unsigned short    reserved3;
  49.  
  50.     unsigned char    tokens[1];    // the RLE token data (variable size array)
  51. };
  52.  
  53. typedef struct RLEPixelData        RLEPixelData,*RLEPixelDataPtr,**RLEPixelDataHdl;
  54.  
  55. #define kRLEResourceType        'RLE#'
  56. #define kRLEResourceHeaderSize    (sizeof(RLEPixelData) - sizeof(unsigned char))
  57.  
  58. #if PRAGMA_ALIGN_SUPPORTED
  59.     #pragma options align=reset
  60. #endif
  61.  
  62. ///--------------------------------------------------------------------------------------
  63. //    Function prototypes for the DrawProcs that work in 8-bit, 16-bit, and 32-bit
  64. ///--------------------------------------------------------------------------------------
  65.  
  66. SW_FUNC void BlitPixieRectDrawProc(
  67.     FramePtr srcFrameP,
  68.     FramePtr dstFrameP,
  69.     Rect* srcRect,
  70.     Rect* dstRect);
  71.  
  72. SW_FUNC void BlitPixieClearDrawProc(
  73.     FramePtr srcFrameP,
  74.     FramePtr dstFrameP,
  75.     Rect* srcRect,
  76.     Rect* dstRect);
  77.  
  78. SW_FUNC void BlitPixieMaskDrawProc(
  79.     FramePtr srcFrameP,
  80.     FramePtr dstFrameP,
  81.     Rect* srcRect,
  82.     Rect* dstRect);
  83.  
  84. SW_FUNC void BlitPixiePartialMaskDrawProc(
  85.     FramePtr srcFrameP,
  86.     FramePtr dstFrameP,
  87.     Rect* srcRect,
  88.     Rect* dstRect);
  89.  
  90. SW_FUNC Boolean BlitPixieMaskCollisionProc(
  91.     SpritePtr srcSpriteP,
  92.     SpritePtr dstSpriteP,
  93.     Rect* srcRect,
  94.     Rect* dstRect);
  95.  
  96. SW_FUNC void BlitPixieMaskColorDrawProc(
  97.     FramePtr srcFrameP,
  98.     FramePtr dstFrameP,
  99.     Rect* srcRect,
  100.     Rect* dstRect);
  101.  
  102.  
  103. SW_FUNC void BlitPixieRLEDrawProc(
  104.     FramePtr srcFrameP,
  105.     FramePtr dstFrameP,
  106.     Rect* srcRect,
  107.     Rect* dstRect);
  108.  
  109. SW_FUNC Boolean BlitPixieRLECollisionProc(
  110.     SpritePtr srcSpriteP,
  111.     SpritePtr dstSpriteP,
  112.     Rect* srcRect,
  113.     Rect* dstRect);
  114.  
  115. SW_FUNC void BlitPixieRLEColorDrawProc(
  116.     FramePtr srcFrameP,
  117.     FramePtr dstFrameP,
  118.     Rect* srcRect,
  119.     Rect* dstRect);
  120.  
  121.  
  122. SW_FUNC void BlitPixieFlipRectDrawProc(
  123.     FramePtr srcFrameP,
  124.     FramePtr dstFrameP,
  125.     Rect* srcRect,
  126.     Rect* dstRect);
  127.  
  128. SW_FUNC void BlitPixieFlipMaskDrawProc(
  129.     FramePtr srcFrameP,
  130.     FramePtr dstFrameP,
  131.     Rect* srcRect,
  132.     Rect* dstRect);
  133.  
  134. SW_FUNC Boolean BlitPixieFlipMaskCollisionProc(
  135.     SpritePtr srcSpriteP,
  136.     SpritePtr dstSpriteP,
  137.     Rect* srcRect,
  138.     Rect* dstRect);
  139.     
  140. SW_FUNC void BlitPixieFlipMaskColorDrawProc(
  141.     FramePtr srcFrameP,
  142.     FramePtr dstFrameP,
  143.     Rect* srcRect,
  144.     Rect* dstRect);
  145.  
  146. ///--------------------------------------------------------------------------------------
  147. //    Function prototypes for compiled sprite DrawProcs (68k only)
  148. ///--------------------------------------------------------------------------------------
  149.  
  150. SW_FUNC void BlitPixieCompiledSpriteDrawProc(
  151.     FramePtr srcFrameP,
  152.     FramePtr dstFrameP,
  153.     Rect *srcRect,
  154.     Rect *dstRect);
  155.  
  156. ///--------------------------------------------------------------------------------------
  157. //    Function prototypes for the all-bit DrawProcs (68k only)
  158. ///--------------------------------------------------------------------------------------
  159.  
  160. SW_FUNC void BlitPixieAllBitRectDrawProc(
  161.     FramePtr srcFrameP,
  162.     FramePtr dstFrameP,
  163.     Rect *srcRect,
  164.     Rect *dstRect);
  165.  
  166. SW_FUNC void BlitPixieAllBitMaskDrawProc(
  167.     FramePtr srcFrameP,
  168.     FramePtr dstFrameP,
  169.     Rect *srcRect,
  170.     Rect *dstRect);
  171.  
  172. SW_FUNC void BlitPixieAllBitPartialMaskDrawProc(
  173.     FramePtr srcFrameP,
  174.     FramePtr dstFrameP,
  175.     Rect *srcRect,
  176.     Rect *dstRect);
  177.  
  178. ///--------------------------------------------------------------------------------------
  179. //    Function prototype for the double-rect DrawProc (works in 8-bit, 16-bit, and 32-bit)
  180. ///--------------------------------------------------------------------------------------
  181.  
  182. SW_FUNC void BlitPixieDoubleRectDrawProc(
  183.     FramePtr srcFrameP,
  184.     FramePtr dstFrameP,
  185.     Rect* srcRectA,
  186.     Rect* dstRectA,
  187.     Rect* srcRectB,
  188.     Rect* dstRectB);
  189.  
  190. ///--------------------------------------------------------------------------------------
  191. //    Function prototypes for misc stuff (GetPixel, SetPixel, star field stuff, etc.)
  192. ///--------------------------------------------------------------------------------------    
  193.  
  194. SW_FUNC unsigned long SWGetValueFromColor(
  195.     FramePtr dstFrameP,
  196.     RGBColor *color);
  197.     
  198. SW_FUNC void SWGetColorFromValue(
  199.     FramePtr dstFrameP,
  200.     RGBColor *color,
  201.     unsigned long pixelValue);
  202.  
  203. SW_FUNC void SWSetPixel(
  204.     FramePtr        dstFrameP,
  205.     short            x,
  206.     short            y,
  207.     unsigned long    color);
  208.  
  209. SW_FUNC unsigned long SWGetPixel(
  210.     FramePtr        dstFrameP,
  211.     short            x,
  212.     short            y );
  213.  
  214. SW_FUNC void SWAnimateStarField(
  215.     SpriteWorldPtr    spriteWorldP,
  216.     StarArray        *starArray,
  217.     short            numStars,
  218.     unsigned long    backColor);
  219.  
  220.  
  221. //------------------------------------------------------------------------------------------------
  222. //    Pixel pointer macros
  223. ///-----------------------------------------------------------------------------------------------
  224.  
  225. long  SW_ROWBYTES(FramePtr frame, int rows);            // rows to bytes
  226. long  SW_PIXELBYTES(FramePtr frame, int pixels);        // pixels to bytes
  227. Ptr   SW_PIXELPTR(FramePtr frame, int x, int y);        // get pointer to a pixel
  228.  
  229.     // special cases of SW_PIXELPTR:
  230. UInt8  *SW_PIXELPTR8(FramePtr frame, int x, int y);        // get pointer to a 8-bit pixel
  231. UInt16 *SW_PIXELPTR16(FramePtr frame, int x, int y);    // get pointer to a 16-bit pixel
  232. UInt32 *SW_PIXELPTR32(FramePtr frame, int x, int y);    // get pointer to a 32-bit pixel
  233.  
  234.  
  235. /*    SW_ASSERT( rows >= (frame)->frameRect.top && rows < (frame)->frameRect.bottom )            */
  236. #define SW_ROWBYTES(frame,rows)            ( (frame)->scanLinePtrArray[ (rows) - (frame)->frameRect.top ] )
  237. //#define SW_ROWBYTES(frame,rows)        ( (rows) * (frame)->frameRowBytes )            // <-- unoptimized
  238.  
  239. /*    SW_ASSERT( pixels >= (frame)->frameRect.left && pixels < (frame)->frameRect.right )        */
  240. #define SW_PIXELBYTES(frame,pixels)        ( (pixels) << (frame)->pixelShift )
  241. //#define SW_PIXELBYTES(frame,pixels)    ( ((pixels) * (frame)->frameDepth) >> 3 )    // <-- unoptimized
  242.  
  243. /*    SW_ASSERT( x >= (frame)->frameRect.left && x < (frame)->frameRect.right )
  244.     SW_ASSERT( y >= (frame)->frameRect.top  && y < (frame)->frameRect.bottom )        */
  245. #define SW_PIXELPTR(frame,x,y)        \
  246.     ( (frame)->frameBaseAddr + SW_ROWBYTES(frame,y) + SW_PIXELBYTES(frame,x) )
  247.  
  248.  
  249. #define SW_PIXELPTR8(frame,x,y)        \
  250.     ((UInt8  *) ( (frame)->frameBaseAddr + SW_ROWBYTES(frame,y) + (x) ))
  251.  
  252. #define SW_PIXELPTR16(frame,x,y)        \
  253.     ((UInt16 *) ( (frame)->frameBaseAddr + SW_ROWBYTES(frame,y) + ((x)+(x)) ))
  254.  
  255. #define SW_PIXELPTR32(frame,x,y)        \
  256.     ((UInt32 *) ( (frame)->frameBaseAddr + SW_ROWBYTES(frame,y) + ((x)<< 2) ))
  257.  
  258.  
  259. //------------------------------------------------------------------------------------------------
  260. //    Bit-fiddling macros, avoiding conditionals and tables      
  261. ///-----------------------------------------------------------------------------------------------
  262.  
  263. void  SW_BITSET(Ptr byteptr, int bitnum);                        // set a bit (1)
  264. void  SW_BITCLR(Ptr byteptr, int bitnum);                        // clear a bit (0)
  265. Boolean SW_BITTST(Ptr byteptr, int bitnum);                        // test a bit
  266.  
  267. void  SW_NIBBLESET(Ptr byteptr, int nibblenum, char nibble);    // set a nibble (0-F)
  268. char  SW_NIBBLEGET(Ptr byteptr, int nibblenum);                    // get a nibble
  269.  
  270.  
  271. #define SW_BITSET(p,n)             (p)[n >> 3] |= 0x80U >> (n & 7)
  272. #define SW_BITCLR(p,n)             (p)[n >> 3] &= ~(0x80U >> (n & 7))
  273. #define SW_BITTST(p,n)            ((p)[n >> 3] & (0x80U >> (n & 7))) != 0
  274.  
  275.     // (besides Perl this has to be the hairiest piece of code I've ever written :-)   -- afb
  276.  
  277. #define SW_NIBBLEGET(p,n)        (((p)[n >> 1] & ~(0x0F << ((n & 1) << 2))) >> (((~n) & 1) << 2))
  278. //#define SW_NIBBLEGET(p,n)        (n & 1) ? ((p[n>>1]>>4) & 0x0F) : ((p[n>>1] & 0x0F)    // <-- unoptimized
  279.  
  280. #define SW_NIBBLESET(p,n,c)        (p)[n >> 1] = ( ((c) & 0x0F) << (((~n) & 1) << 2) ) |         \
  281.                                                 ((p)[n >> 1] & (0x0F << ((n & 1) << 2)) )
  282. //#define SW_NIBBLESET(p,n,c)    p[n>>1] = (n & 1) ?    (((c & 0x0F) << 4) | (p[n>>1] & 0x0F) : \
  283.                                                     ((p[n>>1] & 0xF0) | (c & 0x0F))    // <-- unoptimized
  284.  
  285. //------------------------------------------------------------------------------------------------
  286. //    24-bit memory mode macros, for the 68K
  287. ///-----------------------------------------------------------------------------------------------
  288.  
  289. extern SInt8 gSWmmuMode;    
  290.  
  291. #if SW_68K
  292.  
  293. #include <OSUtils.h>
  294.  
  295. #define START_32_BIT_MODE    \
  296.     {    \
  297.         SInt8 mmuMode;    \
  298.         if (gSWmmuMode != true32b) \
  299.         {    \
  300.             mmuMode = true32b;    \
  301.             SwapMMUMode(&mmuMode);    \
  302.         }    
  303. #define END_32_BIT_MODE    \
  304.         if (gSWmmuMode != true32b)     \
  305.         {    \
  306.             SwapMMUMode(&mmuMode);    \
  307.         }    \
  308.     }
  309.  
  310. #else
  311.  
  312. #define START_32_BIT_MODE    // we're always in 32-bit mode on PPC
  313. #define END_32_BIT_MODE
  314.  
  315. #endif
  316.  
  317. ///--------------------------------------------------------------------------------------
  318. //    Rect macros
  319. ///--------------------------------------------------------------------------------------
  320.  
  321. void BP_CLIP_RECT(RectPtr frameRectP, Rect srcRect, Rect dstRect);
  322. Boolean BP_EQUAL_RECT(Rect srcRect, Rect dstRect);
  323.  
  324.  
  325.     // Clips dstRect and srcRect with frameRect.
  326. #define BP_CLIP_RECT(frameRectP, srcRect, dstRect) \
  327.     /* clip off the top so we don't write into random memory */ \
  328.     if (dstRect.top < frameRectP->top) \
  329.     { \
  330.         srcRect.top += frameRectP->top - dstRect.top; \
  331.         dstRect.top =  frameRectP->top; \
  332.     } \
  333.     /* clip off the bottom */ \
  334.     if (dstRect.bottom > frameRectP->bottom) \
  335.     { \
  336.         srcRect.bottom -= dstRect.bottom - frameRectP->bottom; \
  337.         dstRect.bottom = frameRectP->bottom; \
  338.     } \
  339.     /* Make sure height is valid */ \
  340.     if (dstRect.bottom <= dstRect.top) \
  341.         return; \
  342.     /* clip off the left */ \
  343.     if (dstRect.left < frameRectP->left) \
  344.     { \
  345.         srcRect.left += frameRectP->left - dstRect.left; \
  346.         dstRect.left = frameRectP->left; \
  347.     } \
  348.     /* clip off the right */ \
  349.     if (dstRect.right > frameRectP->right) \
  350.     { \
  351.         srcRect.right -= dstRect.right - frameRectP->right; \
  352.         dstRect.right = frameRectP->right; \
  353.     }    \
  354.     /* Make sure width is valid */ \
  355.     if (dstRect.right <= dstRect.left) \
  356.         return; \
  357.     
  358.     // check if two rects are equal
  359. #define BP_EQUAL_RECT( srcRect, dstRect ) \
  360.     (srcRect.top == dstRect.top &&  \
  361.      srcRect.bottom == dstRect.bottom &&  \
  362.      srcRect.left == dstRect.left &&  \
  363.      srcRect.right == dstRect.right )
  364.  
  365.  
  366. #endif // __BLITPIXIEINTERFACE__
  367.